<?php
namespace Home\Controller;

/**
 * 美住微预定房间信息设置接口
 * @modify trainyao 2016-04-29 创建
 */

class RoomSettingController extends ParentController
{
    private $hasRight = true;

    protected function _initialize() {
        parent::_initialize();
        $this->validateUtil = new \Org\Util\Validate();

        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            $this->hasRight = false;
        }
        $hotelId = $param['hotel'];
        // 校验权限,目前只有超级管理员能访问
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $result = $adminAuthorityLogic->check($hotelId);
        if ($result == false) {
            $this->hasRight = false;
        }
        // 检查客栈是否已过期
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            $this->hasRight = false;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            $this->hasRight = false;
        }
    }

    /**
     * 获取房型上架信息
     * @modify trainyao 2016-04-29    创建
     */
    public function roomType() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');

        // 校验是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $roomTypeInfo = $roomTypeBookLogic->getInfo($hotelId);

        // 处理数据
        foreach ($roomTypeInfo as &$roomTypeInfoItem) {
            unset($roomTypeInfoItem['isdelete']);
            unset($roomTypeInfoItem['hotelentity_id']);
            $roomTypeInfoItem['coverImageUrl'] = isset($roomTypeInfoItem['onlineData']['coverimageurl']) ? $roomTypeInfoItem['onlineData']['coverimageurl'] : '';
            $roomTypeInfoItem['description'] = isset($roomTypeInfoItem['onlineData']['description']) ? $roomTypeInfoItem['onlineData']['description'] : '';
            $roomTypeInfoItem['price'] = isset($roomTypeInfoItem['onlineData']['price']) ? $roomTypeInfoItem['onlineData']['price'] : 0.00;
            $roomTypeInfoItem['picture'] = isset($roomTypeInfoItem['onlineData']['picture']) ? array_column($roomTypeInfoItem['onlineData']['picture'], 'name') : array();

            unset($roomTypeInfoItem['onlineData']);
        }
        unset($roomTypeInfoItem);

        returnJson(200, 200, $roomTypeInfo);
    }

    /**
     * 上架房型
     * @modify trainyao 2016-04-29    创建
     */
    public function enableRoomType() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'roomType' => 'notnull,notempty,concatId',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        try {
            $hotelBookLogic->checkCanEnableRoomType($hotelId);
        } catch (\Exception $e) {
            returnJson($e->getMessage());
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        // 检查是否有房间权限操作房型
        if (!$roomTypeLogic->checkHasRight($hotelId, $roomTypeId)) {
            returnJson(403, 202);
            return;
        }

        // 校验是否可启用(至少需设置封面和设置价格)
        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $roomTypeDetail = $roomTypeBookLogic->getInfo($hotelId);
        $roomTypeDetail = getArrayValueAsIndex($roomTypeDetail, 'id');
        foreach ($roomTypeId as $roomTypeIdItem) {
            $roomTypeDetailItem = $roomTypeDetail[$roomTypeIdItem];
            if (empty($roomTypeDetail) || (empty($roomTypeDetailItem['onlineData']['coverimageurl']))) {
                returnJson(403, 305);
                return;
            }
        }
        unset($roomTypeIdItem);

        $enableResult = $roomTypeBookLogic->enableRoomType($hotelId, $roomTypeId);
        if (empty($enableResult)) {
            return;
        }
        returnJson(200, 200);
    }


    /**
     * 下架房间
     * @modify trainyao 2016-04-29    创建
     */
    public function disableRoomType() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'roomType' => 'notnull,notempty,concatId',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        // 检查是否有房间权限操作房型
        if (!$roomTypeLogic->checkHasRight($hotelId, $roomTypeId)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $enableResult = $roomTypeBookLogic->diableRoomType($hotelId, $roomTypeId);
        if (empty($enableResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 保存房间价格信息
     * @modify trainyao 2016-04-29    创建
     */
    public function saveRoomTypePrice() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'roomType' => 'notnull,notempty,id',
            'price' => 'notnull,notempty,decimal8_2',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $price = abs($param['price']);
        if ((double)$price <= 0.00) {
            returnJson(403, 213);
            return;
        }

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeId = $param['roomType'];
        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $saveResult = $roomTypeBookLogic->saveInfo($hotelId, $roomTypeId, $price, null, null, null);
        if (empty($saveResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 保存房间封面图片信息
     * @modify trainyao 2016-04-29    创建
     */
    public function saveRoomTypeCover() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'roomType' => 'notnull,notempty,id',
            'url' => 'notnull,notempty,nameLength255',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeId = $param['roomType'];
        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $url = $param['url'];
        $saveResult = $roomTypeBookLogic->saveInfo($hotelId, $roomTypeId, null, null, $url, null);
        if (empty($saveResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 保存房间价格描述信息
     * @modify trainyao 2016-04-29    创建
     */
    public function saveRoomTypeDescription() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'roomType' => 'notnull,notempty,id',
            'description' => 'notnull,nameLength100',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeId = $param['roomType'];
        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $description = $param['description'];
        $saveResult = $roomTypeBookLogic->saveInfo($hotelId, $roomTypeId, null, $description, null, null);
        if (empty($saveResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 保存房间价格介绍图片
     * @modify trainyao 2016-04-29    创建
     */
    public function saveRoomTypeImage() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'roomType' => 'notnull,notempty,id',
            'url' => 'notnull',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $url = $param['url'];
        if ($url == '') {
            $url = array();
        } else {
            $url = explode(',', $url);
            foreach ($url as $Item) {
                $validatePass = $this->ajaxValidateReturn($this->validateUtil, $Item, 'nameLength255');
                if (!$validatePass) {
                    return;
                }
            }
            unset($Item);
        }
        // 描述图最多4张
        if (count($url) > 4) {
            returnJson(403, 202);
            return;
        }

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeId = $param['roomType'];
        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $saveResult = $roomTypeBookLogic->saveInfo($hotelId, $roomTypeId, null, null, null, $url);
        if (empty($saveResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 切换客栈预定模式:预定到房型/预定到房间
     * @modify trainyao 2016-07-08    创建
     */
    public function toggleBookMode() {
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'bookMode' => 'notnull,notempty,booleanInt',
        );

        // 校验客栈是否启用微预定
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 修改信息
        $bookMode = $param['bookMode'];
        $hotelDetailModel = D('HotelDetail');
        $toggleResult = $hotelDetailModel->saveInfo($hotelId, null, null, null, null, null, null, null, null, null, null, null, null, null, $bookMode);
        if (empty($toggleResult)) {
            returnJson(500, 506);
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 获取价格日历
     * @add Paddy 2016-11-25 创建
     * @modify wenhui 2016-12-15 增加校验 获取打折后的日历价格
     */
    public function getPriceList() {
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'roomtype_id' => 'notnull,notempty,id'
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            returnJson(403,212,null);
        }

        $roomTypeId = $param['roomtype_id'];

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeInfo = $roomTypeLogic->getPriceList($hotelId, $roomTypeId, false);

        returnJson(200, 200, $roomTypeInfo);
    }

    /**
     * 设置折扣
     * @modify wenhui 2016-12-15 创建
     */
    public function setDiscount() {
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'roomtype_id' => 'notnull,notempty,id',
            'discount' => 'notnull,notempty,decimal4_2',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            returnJson(403,212,null);
        }
        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $roomTypeId = $param['roomtype_id'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $discount = isset($param['discount']) ? $param['discount'] : null;
        $roomTypeInfo = $roomTypeLogic->editInfo($hotelId, $roomTypeId, '', '', '', $discount);

        // 删除房型预定价格
        $hotelRoomTypePriceModel = D('HotelRoomTypePrice');
        $hotelRoomTypePriceList = $hotelRoomTypePriceModel->deleteInfo($roomTypeId);
        // 返回数据
        $roomTypeInfo = $roomTypeLogic->getPriceList($hotelId, $roomTypeId, false);
        returnJson(200, 200, $roomTypeInfo);
    }

    /**
     * 设置预定价格
     * @add Paddy 2016-11-25 创建
     * @modify wenhui 2016-12-15 增加校验
     */
    public function setPrice() {
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'roomtype_id' => 'notnull,notempty,id',
            'price_date' => 'notnull,notempty,id',
            'price' => 'notnull,notempty,decimal8_2',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            returnJson(403,212,null);
        }

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $roomTypeId = $param['roomtype_id'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $date = $param['price_date'];
        $price = $param['price'];

        // 价格不能低于立减优惠金额
        $roomTypeInfo = $roomTypeLogic->getRoomTypeInfoById($roomTypeId);
        $minPrice = $price - $roomTypeInfo['charityprice'];
        if ($roomTypeInfo['minustype'] == 1 && $minPrice < $roomTypeInfo['minusdiscount']) {
            returnJson(403, 312, 'minusdiscount error');
            return;
        }

        $roomTypeLogic->setPrice($hotelId, $roomTypeId, $date, $price);
        returnJson(200, 200, null);
    }
    /**
     * 获取预设价格
     * @add Paddy 2016-12-1 创建
     */
    public function getPriceByHotelId(){
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'date' => 'notnull,notempty,isDate'
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            returnJson(403, 212, null);
        }
        $hotelId = $param['hotel'];
        $date = $param['date'];
        $dateTime = strtotime(date('Y-m-d', strtotime($date)));

        $startTime = $dateTime - 3 * 86400;
        $endTime = $dateTime + 33 * 86400;

        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $priceInfo = $roomTypeLogic->getRoomPrice($hotelId, $startTime, $endTime);

        returnJson(200, 200, $priceInfo);
    }

    /**
     * 设置微预定打立减优惠金额或按比例优惠
     * @modify wenhui 2017-11-22    创建
     */
    public function setBookRoomTypeDiscound() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'roomTypeId' => 'notnull,notempty,id',
            'minustype' => 'notnull,notempty,booleanInt',
        );

        if (isset($param['minustype'])) {
            $validateRule['minustype'] = 'notnull,notempty,id';
        }

        // 立减优惠方式 0=没优惠 1=立减优惠 2=按比例优惠
        if ($param['minustype'] == 2) {
            $validateRule['minusdiscount'] = 'notnull,notempty,decimal4_2';
        } else {
            $validateRule['minusdiscount'] = 'notnull,notempty,decimal8_2';
        }

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $hotelId = $param['hotel'];
        $roomTypeId = $param['roomTypeId'];
        $minusdiscount = $param['minusdiscount'];
        $minustype = $minusdiscount == 0  ? 0 : $param['minustype'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $roomTypeInfo = $roomTypeLogic->getRoomTypeInfoById($roomTypeId);
        // 立减优惠金额不能高于微预定价格日历最低值
        if ($minustype == 1) {
            $priceList = getAllPrice($roomTypeId, date('Y-m-d'), date('Y-m-d', strtotime('+6 month')));
            sort($priceList['priceList'], SORT_NUMERIC);
            $minPrice = $priceList['priceList'][0] - $roomTypeInfo['charityprice'];            
            if ($minusdiscount > $minPrice) {
                returnJson(403, 315, 'minusdiscount error');
            }
        }

        $saveResult = $roomTypeLogic->editInfo($hotelId, $roomTypeId, '', $roomTypeInfo['price'], array(), null, null, $minusdiscount, $minustype);

        returnJson(200, 200, array('minusdiscount' => $minusdiscount, 'minustype' => $minustype));
    }

    /**
     * 会员房费立减优惠开关
     * @modify trainyao 2017-11-23    创建
     */
    public function toggleMinusEnable() {
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'minusEnable' => 'notnull,notempty,booleanInt',
        );

        // 校验客栈是否启用微预定
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 修改信息
        $minusEnable = $param['minusEnable'];
        $hotelDetailModel = D('HotelDetail');
        $toggleResult = $hotelDetailModel->saveInfo($hotelId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, $minusEnable);
        if (empty($toggleResult)) {
            returnJson(500, 506);
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 保存客栈货币
     * @modify wenhui 2017-12-19 创建
     */
    public function setHotelCurrency() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'currencyId' => 'notnull,notempty,id',
        );

        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $hotelId = $param['hotel'];
        $currencyId = $param['currencyId'];

        // 校验客栈是否启用微预定
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $currencyLogic = A('Common/Currency', 'Logic');
        try {
            $addResult = $currencyLogic->addHotelCurrency($hotelId, $currencyId, 0);
        } catch (\Exception $e) {
            returnJson($e->getMessage());
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 保存客栈货币
     * @modify wenhui 2017-12-19 创建
     */
    public function editHotelCurrency() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'currencyId' => 'notnull,notempty,id',
            'hotelCurrencyId' => 'notnull,notempty,id',
        );

        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $hotelId = $param['hotel'];
        $currencyId = $param['currencyId'];
        $hotelCurrencyId = $param['hotelCurrencyId'];

        // 校验客栈是否启用微预定
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $currencyLogic = A('Common/Currency', 'Logic');
        try {
            $addResult = $currencyLogic->saveHotelCurrency($hotelCurrencyId, $currencyId);
        } catch (\Exception $e) {
            returnJson($e->getMessage());
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 保存客栈货币
     * @modify wenhui 2017-12-19 创建
     */
    public function deleteHotelCurrency() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'hotelCurrencyId' => 'notnull,notempty,id',
        );

        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $hotelId = $param['hotel'];
        $hotelCurrencyId = $param['hotelCurrencyId'];

        // 校验客栈是否启用微预定
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $currencyLogic = A('Common/Currency', 'Logic');
        try {
            $deleteResult = $currencyLogic->saveHotelCurrency($hotelCurrencyId, null, IS_DELETE);
        } catch (\Exception $e) {
            returnJson($e->getMessage());
            return;
        }

        returnJson(200, 200);
    }
}
